<template>
  <view class="body">
    <view class="CNY_bg">
      <image :src="ossImg('others/CNY2023/ldy_bg%402x.png')"></image>

      <view class="CNY_btn" @click="toCNY">
        <image :src="ossImg('others/CNY2023/jkcy_button%402x.png')"></image>
      </view>

      <button open-type="contact" class="CNY_kefu" @click.stop="toKefu">
        <view>
          <image :src="ossImg('others/CNY2023/Lxkf_icon%402x.png')"></image>
        </view>
      </button>

      <view class="toBack" @click.stop="backHome">
        <image :src="ossImg('others/CNY2023/cny_return.png')"></image>
      </view>

      <view class="CNY_text"> 具体规则见活动页面 </view>
    </view>
  </view>


</template>

<script setup>
import { ossImg } from "@/utils/utils";
import { onLoad, onShareAppMessage, onShow } from "@dcloudio/uni-app";
import privacyPopup from "@/components/privacy-popup";

onLoad((options) => {});

onShow(() => {
  getApp().accessLogAdd();
});

const toCNY = () => {
  uni.navigateToMiniProgram({
    appId: "wxd1e64df356bff9e4",
    path: "pages/index/index?from=pubid:wx;aid:landingpage",
    envVersion: "release",
  });
};

const backHome = () => {
  getApp().emdlz2("track", "event", "homepage", "click", "homepage_bottom", "");
  uni.switchTab({
    url: "/pages/home/home",
  });
};

const toKefu = () => {
  getApp().emdlz2("track", "event", "homepage", "click", "customer_service", "");
  getApp().sr().track("start_consult", {
    action_type: "consult_online",
    // more...
  });
};

onShareAppMessage((e) => {
  const pages = getCurrentPages();
  const currentPage = pages[pages.length - 1].route;
  const pageUrl = currentPage;

  const shareObj = {
    title: "一起放烟花，玩出年味道", // 默认是小程序的名称(可以写slogan等)
    path: pageUrl, // 默认是当前页面，必须是以‘/’开头的完整路径
    imageUrl: ossImg("others/CNY2023/CNY-share.jpg"), //自定义图片路径，可以是本地文件路径、代码包文件路径或者网络图片路径，支持PNG及JPG，不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
    success: (res) => {
      // 转发成功之后的回调
      if (res.errMsg == "shareAppMessage:ok") {
      }
    },
    fail: (err) => {
      // 转发失败之后的回调
      console.log("转发失败之后的回调", err);
      if (res.errMsg == "shareAppMessage:fail cancel") {
        // 用户取消转发
        console.log("用户取消转发");
      } else if (res.errMsg == "shareAppMessage:fail") {
        // 转发失败，其中 detail message 为详细失败信息
        console.log("转发失败，其中detail message 为详细失败信息");
      }
    },
    complete: () => {
      // 转发结束之后的回调（转发成不成功都会执行）
      console.log("转发结束之后的回调（转发成不成功都会执行）");
    },
  };
  console.log(shareObj);
  return shareObj;
});
</script>

<style lang="less" scoped>
.body {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;

  .CNY_bg {
    position: relative;
    width: 100%;
    height: 812px;
    image {
      width: 100%;
      height: 100%;
    }

    .CNY_btn {
      position: absolute;
      width: 300px;
      height: 72px;
      top: 456.5px;
      left: 37.5px;
      image {
        width: 100%;
        height: 100%;
      }
    }

    .CNY_kefu {
      position: absolute;
      padding: 0 !important;
      margin: 0 !important;
      border-radius: 0 !important;
      background: none !important;
      top: 185.5px;
      left: 291px;
      width: 84px;
      height: 44px;
      view {
        width: 100%;
        height: 100%;
        image {
          width: 100%;
          height: 100%;
        }
      }
    }

    .CNY_text {
      position: absolute;
      top: 537.5px;
      font-size: 12px;
      text-align: center;
      width: 100%;
      font-weight: bold;
      color: #010101;
    }

    .toBack {
      width: 30px;
      height: 30px;
      position: absolute;
      top: 30px;
      left: 15px;
    }
  }
}
</style>
